package logic

import (
	"context"
	"cp/cprpc/cprpcclient"

	"cp/api/internal/svc"
	"cp/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectionAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCollectionAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectionAddLogic {
	return &CollectionAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CollectionAddLogic) CollectionAdd(req *types.CollectionAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.CpRpc.CollectionAdd(l.ctx, &cprpcclient.CollectionAddRequest{
		UserId:   int64(req.UserId),
		CourseId: int64(req.CourseId),
		Status:   req.Status,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "发布成功",
		Data:    add,
		Code:    200,
	}, nil

}
